﻿/**
 * @file		ct_dd_pmc_uart.c
 * @brief		PMC UART driver Component Test
 * @note		None
 * @attention	None
 * 
 * <B><I>Copyright 2016 Socionext Inc.</I></B>
 */

#include <stdlib.h>
#include <string.h>
#include "driver_common.h"
#include "ct_dd_pmc_uart.h"
#include "dd_pmc_uart.h"
#include "dd_pmc_hdmac.h"
#include "dd_pmc_tmr32.h"
#include "pmc.h"

/*----------------------------------------------------------------------*/
/* Definition															*/
/*----------------------------------------------------------------------*/
#define D_UART_SRC_ADDR			(0x7A000000)	// UART TRANSFER SOURCE BUFFER ADDRESS
#define D_UART_SRC_SIZE			(0x1000)		// UART TRANSFER SOURCE BUFFER SIZE(sizeof(CHAR[4096]))
#define D_UART_SLAVE_ADDR_0		(0x01)			// UART slave address
#define D_UART_SLAVE_ADDR_1		(0x02)			// UART slave address
#define D_UART_SLAVE_ADDR_2		(0x04)			// UART slave address
#define D_UART_SLAVE_ADDR_3		(0x08)			// UART slave address
//#define D_UART_SLAVE_ADDR_4	(0x10)			// UART slave address
#define D_UART_SLAVE_ADDR_5		(0x20)			// UART slave address
#define D_UART_TIMER_CH			(7)

#ifdef CO_DEBUG_ON_PC
#define D_UART_TEST_CMD_LEN		20
#endif	// CO_DEBUG_ON_PC

/*----------------------------------------------------------------------*/
/* Enumeration															*/
/*----------------------------------------------------------------------*/

/*----------------------------------------------------------------------*/
/* Global Data															*/
/*----------------------------------------------------------------------*/
// UART ring buffer
static UCHAR gUart_r_buff[256];
// UART channel
static UCHAR gSend_flg;

#ifdef CO_DEBUG_ON_PC
// UART send buffer
static UCHAR gUart_s_buff[256];

static char* gCmd_Argv[25];
#endif	// CO_DEBUG_ON_PC

#ifdef CO_DEBUG_ON_PC
static void ct_uart_reg_dump(void)
{
	Ddim_Print(("---- UART Register dump ----\n"));
	Ddim_Print(("UART.SMR   = 0x%02x\n", IO_PMC.UART.SMR.byte));
	Ddim_Print(("UART.SCR   = 0x%02x\n", IO_PMC.UART.SCR.byte));
	Ddim_Print(("UART.ESCR  = 0x%02x\n", IO_PMC.UART.ESCR.byte));
	Ddim_Print(("UART.SSR   = 0x%02x\n", IO_PMC.UART.SSR.byte));
	Ddim_Print(("UART.DR    = 0x%04x\n", IO_PMC.UART.DR.hword));
	Ddim_Print(("UART.BGR   = 0x%04x\n", IO_PMC.UART.BGR.hword));
	Ddim_Print(("UART.FCR   = 0x%04x\n", IO_PMC.UART.FCR.hword));
	Ddim_Print(("UART.FBYTE = 0x%04x\n", IO_PMC.UART.FBYTE.hword));
	Ddim_Print(("----------------------------\n"));
	
	return;
}
#endif	// CO_DEBUG_ON_PC

static VOID  send_callback()
{
	Ddim_Print(("UART Send Callback\n"));
}

static VOID  send_callback_multi()
{
	Ddim_Print(("UART Send Callback(multi)\n"));
}

static VOID  receive_callback( VOID const *const r_result )
{
	INT32 result;
	CHAR  receive_data;

	result = (*(INT32*)r_result);
	if(result == D_DD_PMC_UART_INT_STATUS_RECV_CHAR){
		Dd_PMC_UART_Get_Char( &receive_data );
		Ddim_Print(("UART Receive Callback(echo on). data=%d\n", receive_data));
	}
	else {
		Ddim_Print(("UART Receive Callback(echo on). err=0x%x\n", result));
	}
}

static VOID  receive_callback_echo( VOID const *const r_result )
{
	CHAR  receive_data;

	receive_data = (CHAR)(*(INT32*)r_result);
	Ddim_Print(("UART Receive Callback(echo off). data=%d\n", receive_data));
}

static VOID  receive_callback_multi( VOID const *const r_result )
{
	INT32 result;
	CHAR  receive_data;

	result = (*(INT32*)r_result);
	if( result == D_DD_PMC_UART_INT_STATUS_OVERRUN_ERROR || result == D_DD_PMC_UART_INT_STATUS_FRAMING_ERROR ){
		Ddim_Print(("UART Receive Callback(error). result=0x%08x\n", result));
	}
	else if( result == D_DD_PMC_UART_INT_STATUS_RECV_SLAVE_ADDR ){
		Ddim_Print(("UART Receive Callback(addr). Receive_slave address\n"));
	}
	else{
		receive_data = (CHAR)(*(INT32*)r_result);
		Ddim_Print(("UART Receive Callback(data). result=%02x\n", receive_data));
	}
}

static VOID  receive_callback_dma( VOID const *const r_result )
{
	INT32 result;
	CHAR  receive_data;

	result = (*(INT32*)r_result);
	if(result == D_DDIM_OK){
		Dd_PMC_UART_Get_Char(&receive_data);
	}
}

static VOID ct_send_dma_callback(INT32 status)
{
	Ddim_Print(("ct_send_dma_callback. status=0x%08X\n", status));
}

#if 0
static VOID ct_recv_dma_callback(INT32 status)
{
	Ddim_Print(("ct_recv_dma_callback. status=0x%08X\n", status));
}
#endif

static VOID ct_uart_timer_handler( VOID )
{
	INT32 ret;

	if(gSend_flg == 1){
		ret = Dd_PMC_UART_Stop();
		Ddim_Print(("UART Stop ERR. ret=0x%x\n", ret));
		gSend_flg = 0;
	}
}

static INT32 ct_uart_dma_send_process( UCHAR dma_ch )
{
	INT32 ret= 0;

	ret = Dd_PMC_UART_Put_Str_DMA(dma_ch);
	if( ret != D_DDIM_OK ){
		Ddim_Print( ("Dd_PMC_UART_Put_Str_DMA error=0x%x\n", ret) );
		return -1;
	}

	return 0;
}

static VOID ct_uart_restart_fifo( VOID )
{
	T_DD_PMC_UART_MNG		uart_mng;
	T_DD_PMC_UART_FIFO_CTRL	fifo_ctrl;

	memset( &uart_mng, 0, sizeof(T_DD_PMC_UART_MNG));
	memset( &fifo_ctrl, 0, sizeof(T_DD_PMC_UART_FIFO_CTRL));

	// Set UART control data
	uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;	// Baud rate
	uart_mng.receive_buff_addr	= &gUart_r_buff[0];					// Receive buffer address
	uart_mng.receive_buff_size	= sizeof(gUart_r_buff);				// Receive buffer size
	uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;			// Send_buff_addr
	uart_mng.send_buff_size		= D_UART_SRC_SIZE;					// Send buffer size
	uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_ON;		// Auto Echo
	uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;		// Save to the buffer
	uart_mng.mode				= E_DD_PMC_UART_MODE_NORMAL;		// UART Nomal Mode
	uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;	// Transferring Direction, LSB first or MSB first
	uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;			// Stop bit length
	uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;	// Parity bit type
	uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;		// Data Length
	uart_mng.inv_nrz			= 0;								// NRZ

	fifo_ctrl.fsel				= 0;
	fifo_ctrl.fe1				= 1;
	fifo_ctrl.fe2				= 0;
	fifo_ctrl.flste				= 0;
	fifo_ctrl.fset				= 0;
	fifo_ctrl.fbyte_recv		= 0;
	uart_mng.fifo_ctrl			= &fifo_ctrl;						// FIFO Setting

	// Start UART
	Dd_PMC_UART_Ctrl(&uart_mng);
	Dd_PMC_UART_Start(send_callback, receive_callback_dma);

	return;
}

static VOID ct_uart_restart_fifo2( VOID )
{
	T_DD_PMC_UART_MNG		uart_mng;
	T_DD_PMC_UART_FIFO_CTRL	fifo_ctrl;

	memset( &uart_mng, 0, sizeof(T_DD_PMC_UART_MNG));
	memset( &fifo_ctrl, 0, sizeof(T_DD_PMC_UART_FIFO_CTRL));

	// Set UART control data
	uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;	// Baud rate
	uart_mng.receive_buff_addr	= &gUart_r_buff[0];					// Receive buffer address
	uart_mng.receive_buff_size	= sizeof(gUart_r_buff);				// Receive buffer size
	uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;			// Send_buff_addr
	uart_mng.send_buff_size		= D_UART_SRC_SIZE;					// Send buffer size
	uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_ON;		// Auto Echo
	uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;		// Save to the buffer
	uart_mng.mode				= E_DD_PMC_UART_MODE_NORMAL;		// UART Nomal Mode
	uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;	// Transferring Direction, LSB first or MSB first
	uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;			// Stop bit length
	uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;	// Parity bit type
	uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;		// Data Length
	uart_mng.inv_nrz			= 0;								// NRZ

	fifo_ctrl.fsel				= 0;
	fifo_ctrl.fe1				= 1;
	fifo_ctrl.fe2				= 1;
	fifo_ctrl.flste				= 0;
	fifo_ctrl.fset				= 0;
	fifo_ctrl.fbyte_recv		= 3;
	uart_mng.fifo_ctrl			= &fifo_ctrl;						// FIFO Setting

	// Start UART
	Dd_PMC_UART_Ctrl(&uart_mng);
	Dd_PMC_UART_Start(send_callback, receive_callback_dma);

	return;
}

static INT32 ct_uart_process_multi(UCHAR num)
{
	INT32					ret = D_DDIM_OK;
	T_DD_PMC_UART_MNG		uart_mng;
	T_DD_PMC_UART_FIFO_CTRL	fifo_ctrl;

	memset(&uart_mng, 0, sizeof(T_DD_PMC_UART_MNG));
	memset(&fifo_ctrl, 0, sizeof(T_DD_PMC_UART_FIFO_CTRL));

	switch(num){
		case 1:		// send address(D_UART_SLAVE_ADDR_2) -> send data(FIFO not use)  bit_length:8bit
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			uart_mng.fifo_ctrl			= NULL;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback_multi, receive_callback_multi );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_UART_Send_Target_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Send_Target_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Str( 'U' );
			Dd_PMC_UART_Set_Str( 'A' );
			Dd_PMC_UART_Set_Str( 'R' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( ' ' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( 'E' );
			Dd_PMC_UART_Set_Str( 'S' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( '1' );
			Dd_PMC_UART_Set_Str( '\n' );

			Dd_PMC_UART_Put_Str();

			break;

		case 2:		// send address(D_UART_SLAVE_ADDR_3) -> send data(FIFO use)  bit_length:8bit
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			fifo_ctrl.fsel				= 0;
			fifo_ctrl.fe1				= 1;
			fifo_ctrl.fe2				= 1;
			fifo_ctrl.flste				= 0;
			fifo_ctrl.fset				= 0;
			fifo_ctrl.fbyte_recv		= 1;
			uart_mng.fifo_ctrl			= &fifo_ctrl;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_UART_Send_Target_Slave_Addr( D_UART_SLAVE_ADDR_3 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Send_Target_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Str( 'U' );
			Dd_PMC_UART_Set_Str( 'A' );
			Dd_PMC_UART_Set_Str( 'R' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( ' ' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( 'E' );
			Dd_PMC_UART_Set_Str( 'S' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( '2' );
			Dd_PMC_UART_Set_Str( '\n' );

			Dd_PMC_UART_Put_Str();

			break;

		case 3:		// send address(D_UART_SLAVE_ADDR_2) -> send data(FIFO use)  bit_length:7bit
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_7;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			fifo_ctrl.fsel				= 0;
			fifo_ctrl.fe1				= 1;
			fifo_ctrl.fe2				= 1;
			fifo_ctrl.flste				= 0;
			fifo_ctrl.fset				= 0;
			fifo_ctrl.fbyte_recv		= 1;
			uart_mng.fifo_ctrl			= &fifo_ctrl;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_UART_Send_Target_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Send_Target_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Str( 'U' );
			Dd_PMC_UART_Set_Str( 'A' );
			Dd_PMC_UART_Set_Str( 'R' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( ' ' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( 'E' );
			Dd_PMC_UART_Set_Str( 'S' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( '3' );
			Dd_PMC_UART_Set_Str( '\n' );

			Dd_PMC_UART_Put_Str();

			break;

		case 4:		// send address(D_UART_SLAVE_ADDR_3) -> send data(FIFO not use)  bit_length:7bit
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_7;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			uart_mng.fifo_ctrl			= NULL;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}
			ret = Dd_PMC_UART_Send_Target_Slave_Addr( D_UART_SLAVE_ADDR_3 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Send_Target_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Str( 'U' );
			Dd_PMC_UART_Set_Str( 'A' );
			Dd_PMC_UART_Set_Str( 'R' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( ' ' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( 'E' );
			Dd_PMC_UART_Set_Str( 'S' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( '4' );
			Dd_PMC_UART_Set_Str( '\n' );

			Dd_PMC_UART_Put_Str();

			break;

		case 10:		// send data
			Dd_PMC_UART_Set_Str( 'U' );
			Dd_PMC_UART_Set_Str( 'A' );
			Dd_PMC_UART_Set_Str( 'R' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( ' ' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( 'E' );
			Dd_PMC_UART_Set_Str( 'S' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( 'A' );
			Dd_PMC_UART_Set_Str( '\n' );
	
			Dd_PMC_UART_Put_Str();
			break;

		case 20:		// receive data(FIFO not use)  bit_length:8bit
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			uart_mng.fifo_ctrl			= NULL;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Set_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}
			break;

		case 21:		// receive data(FIFO use)  bit_length:8bit
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			fifo_ctrl.fsel				= 0;
			fifo_ctrl.fe1				= 1;
			fifo_ctrl.fe2				= 1;
			fifo_ctrl.flste				= 0;
			fifo_ctrl.fset				= 0;
			fifo_ctrl.fbyte_recv		= 1;
			uart_mng.fifo_ctrl			= &fifo_ctrl;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Set_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}
			break;

		case 22:		// receive data(FIFO use)  bit_length:7bit
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_7;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			fifo_ctrl.fsel				= 0;
			fifo_ctrl.fe1				= 1;
			fifo_ctrl.fe2				= 1;
			fifo_ctrl.flste				= 0;
			fifo_ctrl.fset				= 0;
			fifo_ctrl.fbyte_recv		= 1;
			uart_mng.fifo_ctrl			= &fifo_ctrl;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Set_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}
			break;

		case 23:		// receive data(FIFO not use)  bit_length:7bit
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_7;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			uart_mng.fifo_ctrl			= NULL;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Set_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}
			break;

		case 30:		// send address(D_UART_SLAVE_ADDR_1) -> send address(D_UART_SLAVE_ADDR_2) -> timeout -> stop  bit_length:8bit
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			uart_mng.fifo_ctrl			= NULL;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_UART_Start( send_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_UART_Send_Target_Slave_Addr( D_UART_SLAVE_ADDR_1 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Send_Target_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_TMR32_SetTimer( 150*1000, ct_uart_timer_handler );
			if(ret != D_DDIM_OK) {
				Dd_PMC_TMR32_Stop();
				Ddim_Print(("timer set error : ret=%d \n", ret));
				return ret;
			}

			gSend_flg = 1;
			ret = Dd_PMC_TMR32_Start();
			if(ret != D_DDIM_OK) {
				gSend_flg = 0;
				Ddim_Print(("timer start error : ret=%d \n", ret));
				return ret;
			}

			ret = Dd_PMC_UART_Send_Target_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			Dd_PMC_TMR32_Stop();
			gSend_flg = 0;
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Send_Target_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			break;

		case 101:	// Slave Start
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_DIS;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			fifo_ctrl.fsel				= 0;
			fifo_ctrl.fe1				= 1;
			fifo_ctrl.fe2				= 1;
			fifo_ctrl.flste				= 0;
			fifo_ctrl.fset				= 0;
//			fifo_ctrl.fbyte_recv		= 128;
			fifo_ctrl.fbyte_recv		= 64;
			uart_mng.fifo_ctrl			= &fifo_ctrl;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Set_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( ct_send_dma_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}
			break;

		case 102:	// Master Start
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_DIS;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			fifo_ctrl.fsel				= 0;
			fifo_ctrl.fe1				= 1;
			fifo_ctrl.fe2				= 1;
			fifo_ctrl.flste				= 0;
			fifo_ctrl.fset				= 0;
//			fifo_ctrl.fbyte_recv		= 128;
			fifo_ctrl.fbyte_recv		= 64;
			uart_mng.fifo_ctrl			= &fifo_ctrl;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback, receive_callback_dma );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_UART_Send_Target_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Send_Target_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			break;

#if 0
		case 103:	// interrupt disable
			Dd_PMC_UART_Send_Recv_Disable();
			break;

		case 104:	// Send DMA		data_size = 0x80
			ret = Dd_PMC_UART_Set_Send_Data_DMA( (UCHAR*)0x80000000, 0x80 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Set_Send_Data_DMA error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_UART_Start_Send_DMA( 0 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start_Send_DMA error=0x%x\n", ret) );
				return ret;
			}
			break;

		case 105:	// Send DMA		data_size = 0x3FC000
			ret = Dd_PMC_UART_Set_Send_Data_DMA( (UCHAR*)0x80000000, 0x3FC000 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Set_Send_Data_DMA error=0x%x\n", ret) );
				return ret;
			}
			
			ret = Dd_PMC_UART_Start_Send_DMA( 0 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start_Send_DMA error=0x%x\n", ret) );
				return ret;
			}
			break;

		case 106:	// Recv DMA		data_size = 0x80
			ret = Dd_PMC_UART_Set_Recv_Data_DMA( (UCHAR*)0x80000000, 0x80 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Set_Recv_Data_DMA error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_UART_Start_Recv_DMA( 0 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start_Recv_DMA error=0x%x\n", ret) );
				return ret;
			}
			break;
		case 107:	// Recv DMA		data_size = 0x3FC000
			ret = Dd_PMC_UART_Set_Recv_Data_DMA( (UCHAR*)0x80000000, 0x3FC000 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Set_Recv_Data_DMA error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_UART_Start_Recv_DMA( 0 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start_Recv_DMA error=0x%x\n", ret) );
				return ret;
			}
			break;
#endif

		case 108:
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			fifo_ctrl.fsel				= 0;
			fifo_ctrl.fe1				= 1;
			fifo_ctrl.fe2				= 1;
			fifo_ctrl.flste				= 0;
			fifo_ctrl.fset				= 0;
			fifo_ctrl.fbyte_recv		= 1;
			uart_mng.fifo_ctrl			= &fifo_ctrl;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Set_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}
			break;

		case 109:
			/* Control */
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_MULTI;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;

			fifo_ctrl.fsel				= 0;
			fifo_ctrl.fe1				= 1;
			fifo_ctrl.fe2				= 1;
			fifo_ctrl.flste				= 0;
			fifo_ctrl.fset				= 0;
			fifo_ctrl.fbyte_recv		= 1;
			uart_mng.fifo_ctrl			= &fifo_ctrl;

			ret = Dd_PMC_UART_Ctrl( &uart_mng );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Ctrl error=0x%x\n", ret) );
				return ret;
			}

			/* Start */
			ret = Dd_PMC_UART_Start( send_callback, receive_callback_echo );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Start error=0x%x\n", ret) );
				return ret;
			}

			ret = Dd_PMC_UART_Send_Target_Slave_Addr( D_UART_SLAVE_ADDR_2 );
			if( ret != D_DDIM_OK ){
				Ddim_Print( ("Dd_PMC_UART_Send_Target_Slave_Addr error=0x%x\n", ret) );
				return ret;
			}

			Dd_PMC_UART_Set_Str( 'U' );
			Dd_PMC_UART_Set_Str( 'A' );
			Dd_PMC_UART_Set_Str( 'R' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( ' ' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( 'E' );
			Dd_PMC_UART_Set_Str( 'S' );
			Dd_PMC_UART_Set_Str( 'T' );
			Dd_PMC_UART_Set_Str( '3' );
			Dd_PMC_UART_Set_Str( '\n' );

			Dd_PMC_UART_Put_Str();
			break;

		default:
			break;
	}
	return ret;
}

/**
 * @brief  Command main function for uart test.
 * @param  INT32 argc	:The number of parameters
 *		   CGAR** argv	:The value of parameters
 * @return VOID
 */
VOID Ct_Dd_Pmc_Uart_Main( int argc, char** argv )
{
	int						param2;
	INT32					ret;
	UINT32					length;
	UCHAR					dma_ch;
	UCHAR					num;
	CHAR					data;
	UINT32					count;
	USHORT					baudrate;
	UCHAR					slave_addr;
	ULONG					s_write_pos;
	ULONG					s_over_cnt;
	T_DD_PMC_UART_MNG		uart_mng;

	if( strcmp(argv[1], "ctrl") == 0 ){			// Set CTRL data
		T_DD_PMC_UART_FIFO_CTRL	fifo_ctrl;

		param2 = atoi(argv[2]);
		if (param2 == 0) {
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_NORMAL;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.inv_nrz			= 0;
			fifo_ctrl.fsel				= 0;
			fifo_ctrl.fe1				= 1;
			fifo_ctrl.fe2				= 0;
			fifo_ctrl.flste				= 0;
			fifo_ctrl.fset				= 0;
			fifo_ctrl.fbyte_recv		= 0;
			uart_mng.fifo_ctrl = &fifo_ctrl;
		}
		else if (param2 == 1) {
			uart_mng.baud_rate			= E_DD_PMC_UART_BAUD_RATE_57600;
			uart_mng.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_ON;
			uart_mng.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng.mode				= E_DD_PMC_UART_MODE_NORMAL;
			uart_mng.bit_direction		= E_DD_PMC_UART_BIT_DIR_LSB_FIRST;
			uart_mng.stop_bit_length	= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;
			uart_mng.data_length		= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng.inv_nrz			= 0;
			uart_mng.fifo_ctrl			= NULL;
		}
		else {
			// another pattern setting.
		}
		
		// Call API
		ret = Dd_PMC_UART_Ctrl(&uart_mng);
		if (ret !=D_DDIM_OK) {
			Ddim_Print(("UART Ctrl ERR. ret=0x%x\n", ret));
		}
	}
	else if( strcmp(argv[1], "ctrl_s") == 0 ){			// Set CTRL simple data
		T_DD_PMC_UART_MNG_SIMPLE		uart_mng_simple;

		if (atoi(argv[2]) == 0) {
			uart_mng_simple.baud_rate			= E_DD_PMC_UART_BAUD_RATE_115200;
			uart_mng_simple.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng_simple.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng_simple.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng_simple.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng_simple.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_OFF;
			uart_mng_simple.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_EN;
			uart_mng_simple.stop_bit_length		= E_DD_PMC_UART_STOP_BIT_1;
			uart_mng_simple.data_length			= E_DD_PMC_UART_DATA_LENGTH_8;
			uart_mng_simple.parity_bit			= E_DD_PMC_UART_PARITY_BIT_NONE;
		}
		else {
			uart_mng_simple.baud_rate			= E_DD_PMC_UART_BAUD_RATE_38400;
			uart_mng_simple.receive_buff_addr	= &gUart_r_buff[0];
			uart_mng_simple.receive_buff_size	= sizeof(gUart_r_buff);
			uart_mng_simple.send_buff_addr		= (UCHAR*)D_UART_SRC_ADDR;
			uart_mng_simple.send_buff_size		= D_UART_SRC_SIZE;
			uart_mng_simple.auto_echo			= E_DD_PMC_UART_AUTO_ECHO_ON;
			uart_mng_simple.save_buff			= E_DD_PMC_UART_SAVE2BUFFER_DIS;
			uart_mng_simple.stop_bit_length		= E_DD_PMC_UART_STOP_BIT_2;
			uart_mng_simple.data_length			= E_DD_PMC_UART_DATA_LENGTH_5;
			uart_mng_simple.parity_bit			= E_DD_PMC_UART_PARITY_BIT_EVEN;
		}
		
		// Call API
		ret = Dd_PMC_UART_Initialize_Simple(&uart_mng_simple);
		if (ret !=D_DDIM_OK) {
			Ddim_Print(("Dd_PMC_UART_Initialize_Simple ERR. ret=0x%x\n", ret));
		}
	}
	else if( strcmp(argv[1], "start") == 0 ){

		ret = Dd_PMC_UART_Start( send_callback, receive_callback );
		Ddim_Print(("UART Start OK.\n"));
	}
	else if( strcmp(argv[1], "stop") == 0 ){

		ret = Dd_PMC_UART_Stop();
		Ddim_Print(("UART Stop OK.\n"));
	}
	else if( strcmp(argv[1], "set_test") == 0 ){
		/* Test number */
		num = atoi( argv[2] );
		
		ret = ct_uart_process_multi( num );
		if (ret != D_DDIM_OK) {
			Ddim_Print( ("ct_uart_process ERR. ret=0x%x\n", ret) );
		}
	}
	else if( strcmp(argv[1], "put") == 0 ){

		ret = Dd_PMC_UART_Put_Char( argv[2][0] );
		if (ret != D_DDIM_OK) {
			Ddim_Print( ("Dd_PMC_UART_Put_Char ERR. ret=0x%x\n", ret) );
		}
	}
	else if( strcmp(argv[1], "put_str") == 0 ){
		// Set
		Dd_PMC_UART_Set_Str( 'U' );
		Dd_PMC_UART_Set_Str( 'A' );
		Dd_PMC_UART_Set_Str( 'R' );
		Dd_PMC_UART_Set_Str( 'T' );
		Dd_PMC_UART_Set_Str( ' ' );
		Dd_PMC_UART_Set_Str( 'T' );
		Dd_PMC_UART_Set_Str( 'E' );
		Dd_PMC_UART_Set_Str( 'S' );
		Dd_PMC_UART_Set_Str( 'T' );
		Dd_PMC_UART_Set_Str( '\n' );
		
		// Put
		Dd_PMC_UART_Put_Str();
	}
	else if( strcmp(argv[1], "putdma_rw") == 0 ){
		/* channel */
		dma_ch = atoi( argv[2] );

		memset( (INT32*)D_UART_SRC_ADDR, '\0', D_UART_SRC_SIZE);

		// restart
		ct_uart_restart_fifo2();

		Dd_PMC_UART_Set_Str( 'U' );
		Dd_PMC_UART_Set_Str( 'A' );
		Dd_PMC_UART_Set_Str( 'R' );
		Dd_PMC_UART_Set_Str( 'T' );
		Dd_PMC_UART_Set_Str( ' ' );
		Dd_PMC_UART_Set_Str( 'P' );
		Dd_PMC_UART_Set_Str( 'U' );
		Dd_PMC_UART_Set_Str( 'T' );
		Dd_PMC_UART_Set_Str( ' ' );
		Dd_PMC_UART_Set_Str( 'D' );
		Dd_PMC_UART_Set_Str( 'M' );
		Dd_PMC_UART_Set_Str( 'A' );
		Dd_PMC_UART_Set_Str( ' ' );
		Dd_PMC_UART_Set_Str( 'T' );
		Dd_PMC_UART_Set_Str( 'E' );
		Dd_PMC_UART_Set_Str( 'S' );
		Dd_PMC_UART_Set_Str( 'T' );
		Dd_PMC_UART_Set_Str( '\n' );

		ret = ct_uart_dma_send_process( dma_ch );
		if( ret != D_DDIM_OK ){
			return ;
		}
	}
	else if( strcmp(argv[1], "putdma_max_1") == 0 ){
		/* channel */
		dma_ch = atoi( argv[2] );

		memset( (INT32*)D_UART_SRC_ADDR, '\0', D_UART_SRC_SIZE);

		// restart
		ct_uart_restart_fifo();

		for(count = 0; count < 4095; count++) {
			if (count == 4094) {
				Dd_PMC_UART_Set_Str( 'E' );
			}
			else {
				Dd_PMC_UART_Set_Str( 'A' );
			}
		}

		Dd_PMC_UART_Set_Str( '\n' );

		ret = ct_uart_dma_send_process( dma_ch );
		if( ret != D_DDIM_OK ){
			return ;
		}

		Dd_PMC_UART_Set_Str( 'B' );

		ret = ct_uart_dma_send_process( dma_ch );
		if( ret != D_DDIM_OK ){
			return ;
		}

		Dd_PMC_UART_Set_Str( '\n' );
		ret = ct_uart_dma_send_process( dma_ch );
		if( ret != D_DDIM_OK ){
			return ;
		}
	}
	else if( strcmp(argv[1], "putdma_1_max") == 0 ){

		/* channel */
		dma_ch = atoi( argv[2] );

		memset( (INT32*)D_UART_SRC_ADDR, '\0', D_UART_SRC_SIZE);

		// restart
		ct_uart_restart_fifo();

		Dd_PMC_UART_Set_Str( 'B' );

		ret = ct_uart_dma_send_process( dma_ch );
		if( ret != D_DDIM_OK ){
			return ;
		}

		for(count = 0; count < 4095; count++) {
			if (count == 4094) {
				Dd_PMC_UART_Set_Str( 'E' );
			}
			else {
				Dd_PMC_UART_Set_Str( 'A' );
			}
		}
		ret = ct_uart_dma_send_process( dma_ch );
		if( ret != D_DDIM_OK ){
			return ;
		}

		Dd_PMC_UART_Set_Str( '\n' );
		ret = ct_uart_dma_send_process( dma_ch );
		if( ret != D_DDIM_OK ){
			return ;
		}
	}
	else if( strcmp(argv[1], "putdma_rw_0") == 0 ){
		/* channel */
		dma_ch = atoi( argv[2] );

		memset( (INT32*)D_UART_SRC_ADDR, '\0', D_UART_SRC_SIZE);

		// restart
		ct_uart_restart_fifo();

		ret = ct_uart_dma_send_process( dma_ch );
		if( ret != D_DDIM_OK ){
			return ;
		}
	}
	else if( strcmp(argv[1], "putdma_wr") == 0 ){
		/* channel */
		dma_ch = atoi( argv[2] );

		memset( (INT32*)D_UART_SRC_ADDR, '\0', D_UART_SRC_SIZE);

		// restart
		ct_uart_restart_fifo2();

		for(count = 0; count < 3000; count++) {
			Dd_PMC_UART_Set_Str( 'A' );
			if (count == 2999) {
				Dd_PMC_UART_Set_Str(  ' ' );
				Dd_PMC_UART_Set_Str(  'E' );
				Dd_PMC_UART_Set_Str(  'N' );
				Dd_PMC_UART_Set_Str(  'D' );
				Dd_PMC_UART_Set_Str(  '\n' );
			}
		}

		ret = ct_uart_dma_send_process( dma_ch );
		if( ret != D_DDIM_OK ){
			return ;
		}

		for(count = 0; count < 3000; count++) {
			Dd_PMC_UART_Set_Str( 'B' );
			if (count == 2999) {
				Dd_PMC_UART_Set_Str( ' ' );
				Dd_PMC_UART_Set_Str( 'E' );
				Dd_PMC_UART_Set_Str( 'N' );
				Dd_PMC_UART_Set_Str( 'D' );
				Dd_PMC_UART_Set_Str( '\n' );
			}
		}

		ret = ct_uart_dma_send_process( dma_ch );
		if( ret != D_DDIM_OK ){
			return ;
		}
	}
	else if( strcmp(argv[1], "putover") == 0 ){
		ret = D_DDIM_INPUT_PARAM_ERROR;
		length = atoi( argv[3] );
		
		IO_PMC.UART.SCR.bit.TXE	= 0;

		for(count = 0; count < length; count++) {
			ret = Dd_PMC_UART_Set_Str( argv[2][0] );
			if( ret != D_DDIM_OK ){
				IO_PMC.UART.SCR.bit.TXE	= 1;
				Dd_PMC_UART_Put_Str();
				Ddim_Print( ("Dd_PMC_UART_Set_Str error=0x%x\n", ret) );
				return ;
			}
		}
		
		if (ret == D_DDIM_OK) {
			IO_PMC.UART.SCR.bit.TXE	= 1;
		}
	}
	else if( strcmp(argv[1], "send") == 0 ){

		ret = Dd_PMC_UART_Put_Str();
		if( ret != D_DDIM_OK ){
			Ddim_Print( ("Dd_PMC_UART_Put_Str error=0x%x\n", ret) );
			return ;
		}
	}
	else if( strcmp(argv[1], "receive") == 0 ){
		
		// 3s wait : Input characters from the terminal.
		DDIM_User_Dly_Tsk(3000);
		
		ret = Dd_PMC_UART_Get_Char( &data );
		if( ret != D_DDIM_OK ){
			Ddim_Print( ("Dd_PMC_UART_Get_Char error=0x%x\n", ret) );
			return ;
		}
		
		Ddim_Print( ("Dd_PMC_UART_Put_Str - receive data : %c\n", data) );
	}
	else if ( strcmp(argv[1], "get_ctrl") == 0 ){
		T_DD_PMC_UART_FIFO_CTRL fifo_ctrl;

		uart_mng.fifo_ctrl = &fifo_ctrl;

		ret = Dd_PMC_UART_Get_Ctrl(&uart_mng);
		if( ret != D_DDIM_OK ){
			Ddim_Print( ("Dd_PMC_UART_Get_Ctrl error=0x%x\n", ret) );
			return ;
		}

		Ddim_Print(("UART Ctrl_Get OK.\n"));
		Ddim_Print(("UART baud_rate             =%d\n", uart_mng.baud_rate));
		Ddim_Print(("UART receive_buff_addr     =0x%x\n", uart_mng.receive_buff_addr));
		Ddim_Print(("UART receive_buff_size     =%d\n", uart_mng.receive_buff_size));
		Ddim_Print(("UART send_buff_addr        =0x%x\n", uart_mng.send_buff_addr));
		Ddim_Print(("UART send_buff_size        =%d\n", uart_mng.send_buff_size));
		Ddim_Print(("UART auto_echo             =%d\n", uart_mng.auto_echo));
		Ddim_Print(("UART save_buff             =%d\n", uart_mng.save_buff));
		Ddim_Print(("UART mode                  =%d\n", uart_mng.mode));
		Ddim_Print(("UART bit_direction         =%d\n", uart_mng.bit_direction));
		Ddim_Print(("UART stop_bit_length       =%d\n", uart_mng.stop_bit_length));
		Ddim_Print(("UART data_length           =%d\n", uart_mng.data_length));
		Ddim_Print(("UART parity_bit            =%d\n", uart_mng.parity_bit));
		Ddim_Print(("UART inv_nrz               =%d\n", uart_mng.inv_nrz));
		Ddim_Print(("UART fifo_ctrl->fsel       =%d\n", uart_mng.fifo_ctrl->fsel));
		Ddim_Print(("UART fifo_ctrl->flste      =%d\n", uart_mng.fifo_ctrl->flste));
		Ddim_Print(("UART fifo_ctrl->fset       =%d\n", uart_mng.fifo_ctrl->fset));
		Ddim_Print(("UART fifo_ctrl->fe2        =%d\n", uart_mng.fifo_ctrl->fe2));
		Ddim_Print(("UART fifo_ctrl->fe1        =%d\n", uart_mng.fifo_ctrl->fe1));
		Ddim_Print(("UART fifo_ctrl->fbyte_recv =%d\n", uart_mng.fifo_ctrl->fbyte_recv));
	}
	else if ( strcmp( argv[1], "set_brate" ) == 0 ){
		/* baudrate */
		baudrate = atoi( argv[2] );

		ret = Dd_PMC_UART_Set_Baudrate( baudrate);
		if (ret !=D_DDIM_OK) {
			Ddim_Print(("Dd_PMC_UART_Set_Baudrate ERR. ret=0x%x\n", ret));
		}
	}
	else if ( strcmp( argv[1], "get_brate" ) == 0 ){

		ret = Dd_PMC_UART_Get_Baudrate(&baudrate);
		if (ret !=D_DDIM_OK) {
			Ddim_Print(("Dd_PMC_UART_Get_Baudrate ERR. ret=0x%x\n", ret));
		}
		else {
			Ddim_Print(("Dd_PMC_UART_Get_Baudrate: Baudrate=%d\n", baudrate));
		}
	}
	else if ( strcmp( argv[1], "rst_brate" ) == 0 ){

		ret = Dd_PMC_UART_Reset_Baudrate();
		Ddim_Print(("Dd_PMC_UART_Reset_Baudrate OK.\n"));
	}
	else if ( strcmp( argv[1], "set_fset" ) == 0 ){
		/* lost_detect */
		num = atoi( argv[2] );

		ret = Dd_PMC_UART_Save_Send_FIFO_Pointer(num);
		if (ret !=D_DDIM_OK) {
			Ddim_Print(("Dd_PMC_UART_Save_Send_FIFO_Pointer ERR. ret=0x%x\n", ret));
		}
	}
	else if ( strcmp( argv[1], "set_fld" ) == 0 ){

		ret = Dd_PMC_UART_Reload_Send_FIFO_Pointer();
		if (ret !=D_DDIM_OK) {
			Ddim_Print(("Dd_PMC_UART_Reload_Send_FIFO_Pointer ERR. ret=0x%x\n", ret));
		}
	}
	else if ( strcmp( argv[1], "get_fld" ) == 0 ){

		ret = Dd_PMC_UART_Get_Reload_Status();
		Ddim_Print(("Dd_PMC_UART_Get_Reload_Status: FLD = 0x%x\n", ret));
	}
	else if ( strcmp( argv[1], "reset_fifo" ) == 0 ){
		/* fifo_num */
		num = atoi( argv[2] );

		ret = Dd_PMC_UART_Reset_FIFO(num);
		if (ret !=D_DDIM_OK) {
			Ddim_Print(("Dd_PMC_UART_Reset_FIFO ERR. ret=0x%x\n", ret));
		}
	}
	else if ( strcmp( argv[1], "set_slave" ) == 0 ){
		/* slave_addr */
		slave_addr = atoi( argv[2] );

		ret = Dd_PMC_UART_Set_Slave_Addr(slave_addr);
		Ddim_Print(("Dd_PMC_UART_Set_Slave_Addr OK.\n"));
	}
	else if ( strcmp( argv[1], "send_slave" ) == 0 ){
		/* slave_addr */
		slave_addr = atoi( argv[2] );
		T_DD_PMC_UART_MNG	uart_mng_temp;
		uart_mng_temp.fifo_ctrl = NULL;

		Dd_PMC_UART_Get_Ctrl( &uart_mng_temp );
		uart_mng_temp.mode	= E_DD_PMC_UART_MODE_MULTI;
		Dd_PMC_UART_Ctrl( &uart_mng_temp );
//		IO_PMC.UART.SCR.byte |= 0x03;
		Dd_PMC_UART_Start(send_callback_multi, receive_callback_multi);
		
		ret = Dd_PMC_UART_Send_Target_Slave_Addr(slave_addr);
		if (ret !=D_DDIM_OK) {
			Ddim_Print(("Dd_PMC_UART_Send_Target_Slave_Addr ERR. ret=0x%x\n", ret));
		}
	}
	else if ( strcmp( argv[1], "get_s_write_pos" ) == 0 ){

		s_write_pos = Dd_PMC_UART_Get_Send_Write_Pointer_Addr();
		Ddim_Print(("Dd_PMC_UART_Get_Send_Write_Pointer_Addr: s_write_pos=%d\n", s_write_pos));
	}
	else if ( strcmp( argv[1], "get_s_over_cnt" ) == 0 ){

		s_over_cnt = Dd_PMC_UART_Get_Send_Overlap_Count();
		Ddim_Print(("Dd_PMC_UART_Get_Send_Overlap_Count: s_over_cnt=%d\n", s_over_cnt));
	}
	else if (strcmp(argv[1], "err") == 0){
		// Error.
		switch(atoi(argv[2])){
			case 1:
				ret = Dd_PMC_UART_Ctrl( NULL );
				Ddim_Print(("Dd_PMC_UART_Ctrl(): uart_mng is NULL. ret=%X\n", ret ));
				break;

			case 2:
				uart_mng.mode			= E_DD_PMC_UART_MODE_MULTI;
				uart_mng.data_length	= E_DD_PMC_UART_DATA_LENGTH_5;
				ret = Dd_PMC_UART_Ctrl( &uart_mng );
				Ddim_Print(("Dd_PMC_UART_Ctrl(): UART mode/data_length unmatch. ret=%X\n", ret ));
				break;

			case 3:
				ret = Dd_PMC_UART_Get_Ctrl( NULL );
				Ddim_Print(("Dd_PMC_UART_Get_Ctrl(): uart_mng is NULL. ret=%X\n", ret ));
				break;

			case 4:
				ret = Dd_PMC_UART_Get_Baudrate( NULL );
				Ddim_Print(("Dd_PMC_UART_Get_Baudrate(): baud_rate is NULL. ret=%X\n", ret ));
				break;

			case 5:
				ret = Dd_PMC_UART_Save_Send_FIFO_Pointer( 3 );
				Ddim_Print(("Dd_PMC_UART_Save_Send_FIFO_Pointer(): paramter error.\n"));
				break;

			case 6:
				// FIFO Data write.
				IO_PMC.UART.FBYTE.byte[IO_PMC.UART.FCR.bit.FSEL] = 1;
				
				ret = Dd_PMC_UART_Save_Send_FIFO_Pointer( 0 );
				Ddim_Print(("Dd_PMC_UART_Save_Send_FIFO_Pointer(): Data exist error.\n"));
				break;

			case 7:
				IO_PMC.UART.FCR.bit.FLST = 1;
				
				ret = Dd_PMC_UART_Reload_Send_FIFO_Pointer();
				Ddim_Print(("Dd_PMC_UART_Reload_Send_FIFO_Pointer(): Reload data lost. ret=%X\n", ret ));
				break;

			case 8:
				ret = Dd_PMC_UART_Reset_FIFO( 0 );
				Ddim_Print(("Dd_PMC_UART_Reset_FIFO(): paramter error. ret=%X\n", ret ));
				break;

			case 9:
				ret = Dd_PMC_UART_Get_Char( NULL );
				Ddim_Print(("Dd_PMC_UART_Get_Char(): get_char is NULL. ret=%X\n", ret ));
				break;

			case 10:
				ret = Dd_PMC_UART_Initialize_Simple( NULL );
				Ddim_Print(("Dd_PMC_UART_Initialize_Simple(): uart_mng_simple is NULL. ret=%X\n", ret ));
				break;

			case 11:
#if 0
				uart_mng.mode = E_DD_PMC_UART_MODE_NORMAL;
				uart_mng.receive_buff_addr = &gUart_r_buff[0];
				uart_mng.receive_buff_size = 1;
				uart_mng.send_buff_addr = (UCHAR*)D_UART_SRC_ADDR;
				uart_mng.send_buff_size = 1;
				uart_mng.fifo_ctrl = NULL;
				ret = Dd_PMC_UART_Ctrl( &uart_mng );
#endif
				ret = Dd_PMC_UART_Send_Target_Slave_Addr( 0 );
				Ddim_Print(("Dd_PMC_UART_Send_Target_Slave_Addr(): UART mode unmatch. ret=%X\n", ret ));
				break;

			case 12:
				ret = Dd_PMC_UART_Put_Str_DMA( D_DD_PMC_HDMAC_CH_NUM_MAX );
				Ddim_Print(("Dd_PMC_UART_Put_Str_DMA(): DMA CH number error. ret=%X\n", ret ));
				break;
			
			case 13:
				Dd_PMC_UART_Stop();
				ret = Dd_PMC_UART_Put_Char( 0 );
				Ddim_Print( ("Dd_PMC_UART_Put_Char ERR. ret=0x%x\n", ret) );
				
				ret = Dd_PMC_UART_Put_Str();
				Ddim_Print( ("Dd_PMC_UART_Put_Str ERR. ret=0x%x\n", ret) );
				break;
			
			default:
				Ddim_Print( ("please check 2nd parameter!!\n" ) );
		}

	}
	else{
		Ddim_Print( ("please check 1st parameter!!\n" ) );
	}
	return ;
}

